package org.duoyi.striver.service.thread;

import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.duoyi.striver.service.TaskChainItem;
import org.duoyi.striver.service.common.CommonService;

import java.util.List;

@Slf4j
public class MainRunner extends Thread {

    @Getter
    @Setter
    private volatile boolean state;

    private final List<TaskChainItem> tasks;

    public MainRunner(List<TaskChainItem> tasks) {
        super("任务主线程");
        this.tasks = tasks;
    }

    @SneakyThrows
    @Override
    public void run() {
        log.debug("{}启动", this.getName());
        CommonService.bindWindows();
        this.state = true;
        for (TaskChainItem task : tasks) {
            CommonService.closeAllPanel();
            task.startTask();
        }
        CommonService.release();
        log.debug("{}结束", this.getName());
    }


}
